﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace WGM_Client_Silverlight
{
    public partial class ContactListItem : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public bool IsContactOnline { get; set; }
        public string UserName { get; set; }
        private string _displayName;
        private string _displayStatus;
        private string _displayTooltip;
        private string _displayNameColour = Colors.DarkGray.ToString();
        private string _displayHighlightColour = Colors.DarkGray.ToString();
        public string DisplayHighlightColour
        {
            get { return _displayHighlightColour; }
            set
            {
                _displayHighlightColour = value;
                OnPropertyChanged("DisplayHighlightColour");
            }
        }
        public Visibility DisplayStatusVisiblity { get; set; }
        public object ContactData { get; set; }
        public string DisplayNameColour
        {
            get { return _displayNameColour; }
            set
            {
                _displayNameColour = value;
                OnPropertyChanged("DisplayNameColour");
            }
        }
        public bool FlashContact { get; set; }
        public string DisplayName
        {
            get { return _displayName; }
            set
            {
                _displayName = value;
                OnPropertyChanged("DisplayName");
            }
        }
        public string DisplayStatus
        {
            get { return _displayStatus; }
            set
            {
                _displayStatus = value;
                OnPropertyChanged("DisplayStatus");
                if (value == null || value.Trim() == "")
                    DisplayStatusVisiblity = Visibility.Collapsed;
                else
                    DisplayStatusVisiblity = Visibility.Visible;
            }
        }
        public string DisplayTooltip
        {
            get { return _displayTooltip; }
            set
            {
                _displayTooltip = value;
                OnPropertyChanged("DisplayTooltip");
            }
        }
        public void SetContactData(WGM_Service.UserOptions uo)
        {
            DisplayName = uo.DisplayName;
            DisplayStatus = uo.UserStatus;
            DisplayTooltip = HelperFunctions.GetCLToolTip(uo);
            ContactData = uo;
            OnPropertyChanged("ContactData");
            OnPropertyChanged("DisplayStatus");
            OnPropertyChanged("DisplayName");
            OnPropertyChanged("DisplayTooltip");

        }
        public ContactListItem(string userName, string displayName, string displayStatus, string displayToolTip, object contactData)
        {
            IsContactOnline = false;
            _displayName = displayName;
            _displayStatus = displayStatus;
            _displayTooltip = displayToolTip;
            ContactData = contactData;
            UserName = userName;
            DisplayStatusVisiblity = Visibility.Visible;
            if (displayStatus == null || displayStatus.Trim() == "")
                DisplayStatusVisiblity = Visibility.Collapsed;

            FlashContact = false;
        }
        public void SetContactOnline(bool isOnline)
        {
            //if (IsContactOnline != isOnline)
            {
                if (isOnline == true)
                {
                    FlashContactItem();
                    DisplayNameColour = Colors.Green.ToString();
                    DisplayHighlightColour = DisplayNameColour;
                }
                if (isOnline == false)
                {
                    DisplayNameColour = Colors.DarkGray.ToString();
                    DisplayHighlightColour = DisplayNameColour;
                }
                IsContactOnline = isOnline;
                OnPropertyChanged("DisplayNameColour");
            }
        }
        public void FlashContactItem()
        {
            FlashContact = true;
            OnPropertyChanged("FlashContact");
            FlashContact = false;
            OnPropertyChanged("FlashContact");
        }

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }


}
